package leetcode.code1695;

import leetcode.IDebug;

public class Solution implements IDebug {

	public int maximumUniqueSubarray(int[] nums) {
		boolean[] hash = new boolean[(int) 1e4 + 1];
		int l = 0, r = 0;
		int len = nums.length;
		int ans = Integer.MIN_VALUE, cur = 0;
		while (r <= len) {
			int num = r < len ? nums[r] : -1;
			if (r < len && !hash[num]) {
				hash[num] = true;
				cur += num;
			} else {
				ans = Math.max(ans, cur);
				while (l < r && nums[l] != num) {
					int sub = nums[l];
					hash[sub] = false;
					cur -= sub;
					l++;
				}
				if (l != r) {
					l++;
				}
			}
			r++;
		}
		return ans;
	}

	@Override
	public void debug4() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug3() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug2() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug1() {
		// TODO Auto-generated method stub

	}

	public static void main(String[] args) {
		Solution so = new Solution();
		so.debug1();
		so.debug2();
		so.debug3();
		so.debug4();

	}

}
